package com.zy.web.controller.business;

import com.zy.business.domain.TbWorkReport;
import com.zy.business.service.ReportUserService;
import com.zy.business.service.WorkReportService;
import com.zy.common.annotation.Log;
import com.zy.common.annotation.RepeatSubmit;
import com.zy.common.core.controller.BaseController;
import com.zy.common.core.domain.AjaxResult;
import com.zy.common.core.page.TableDataInfo;
import com.zy.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @description: 工作汇报接口
 * @author: whf
 * @create: 2022-11-14 15:46
 **/
@RestController
@Api(tags = "工作汇报接口")
@RequestMapping("/workReport")
public class WorkReportController extends BaseController {

    @Autowired
    private WorkReportService workReportService;

    @Autowired
    private ReportUserService reportUserService;


    @ApiOperation(value = "获取工作汇报列表(我收到的type=copy)")
    @GetMapping("/list")
    public TableDataInfo list(String type) {
        startPage();
        List<TbWorkReport> workReportList = workReportService.list(type);
        return getDataTable(workReportList);
    }

    @ApiOperation(value = "添加汇报")
    @Log(title = "工作汇报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Object add(@RequestBody TbWorkReport workReport){
        return workReportService.addWorkReport(workReport);
    }

    @ApiOperation(value = "修改汇报")
    @Log(title = "工作汇报", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TbWorkReport workReport){
        return workReportService.editWorkReport(workReport);
    }

    @ApiOperation(value = "删除汇报")
    @Log(title = "工作汇报", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{workReportId}")
    public AjaxResult delete(@PathVariable Long workReportId){
        return workReportService.removeWorkReport(workReportId);
    }

    @ApiOperation(value = "根据id获取人员查看状态")
    @GetMapping("/getReadList")
    public AjaxResult getReadList(Long id){
        return reportUserService.getReadList(id);
    }

    @ApiOperation(value = "修改状态为已读")
    @PostMapping("/changeView/{id}")
    public AjaxResult changeView(@PathVariable Long id){
        return reportUserService.changeView(id);
    }

    @ApiOperation(value = "获取工作汇报详情")
    @GetMapping("/getDetail")
    public AjaxResult getDetail(Long reportId){
        return workReportService.getDetail(reportId);
    }
}
